# coding = utf-8

'''
分析3DIRCADB数据集的原始数据信息
'''

import os
import pydicom

#分析voxel space
def analysis_voxel_space():
   root_path = "E:\Dataset\\3Dircadb1"
   for patient in sorted(os.listdir(root_path)):
       patient_path = os.path.join(root_path, patient)
       patient_path = os.path.join(patient_path, "PATIENT_DICOM")
       for item in sorted(os.listdir(patient_path)):
         file_name = os.path.join(patient_path, item)
         data = pydicom.dcmread(file_name)
         voxel_spacing = [float(data.SliceThickness), float(data.PixelSpacing[0]), float(data.PixelSpacing[0])]
         print(patient.split(".")[1], voxel_spacing)
         break


def analysis_voxel_space_linux(case_id):
    root_path = "/datasets/3DIRCADB/3Dircadb1"
    patident_name = "3Dircadb1.{}".format(case_id+1)
    patient_path = os.path.join(root_path, patident_name)
    patient_path = os.path.join(patient_path, "PATIENT_DICOM")
    for item in sorted(os.listdir(patient_path)):
        file_name = os.path.join(patient_path, item)
        data = pydicom.dcmread(file_name)
        voxel_spacing = [float(data.SliceThickness), float(data.PixelSpacing[0]), float(data.PixelSpacing[0])]
        print(voxel_spacing)


if __name__ == '__main__':
    analysis_voxel_space_linux(case_id=0)